﻿using System;
using System.Linq;
using Framework;

namespace Enterprise.Admin.Handle
{
    /// <summary>
    /// 添加文章
    /// </summary>
    public partial class AddArticle : AdminBasePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            object result;
            try
            {
                var title = Fq("CoTitle").SafeToString();
                var content = Fq("CoContent").SafeToString();
                var summary = Fq("CoSummary").SafeToString();
                var reservedUrl = Fq("CoReservedUrl").SafeToString();
                var author = Fq("CoAuthor").SafeToString();
                var articleCategoryId = Fq("CoArticleCategoryId").SafeToInt();
                var language = Fq("CoLanguage").SafeToString();
                var date = Fq("CoDate").SafeToDateTime();
                var isReserved = Fq("CoIsReserved").SafeToBool();
                var isPopular = Fq("CoIsPopular").SafeToBool();
                var isTop = Fq("CoIsTop").SafeToBool();
                var isRecommend = Fq("CoIsRecommend").SafeToBool();
                var coverArticleImageId = Fq("CoCoverImageId").SafeToInt();
                var articleImageIds = Fq("CoArticleImageId").SafeToString().Split(',').Select(o => o.SafeToInt()).ToArray();
                var articleService = new ArticleService();
                articleService.Add(articleCategoryId, title, content, summary, author, language, reservedUrl, date, isRecommend, isReserved, isPopular, isTop, articleImageIds, coverArticleImageId);
                result = new { state = true, message = "添加成功" };
            }
            catch (Exception ex)
            {
                result = new { state = false, message = ex.Message };
            }
            Json(result);
        }
    }
}